<%--
  Created by IntelliJ IDEA.
  User: Dink
  Date: 2022/1/16
  Time: 12:33
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html>
<head>
  <title>手游开发者平台|APP维护</title>
</head>
<link href="${pageContext.request.contextPath}/statics/localcss/appinfolist.css" rel="stylesheet"/>
<script src="../../statics/js/jquery.js"></script>
<body>
<%@ include file="comment/header.jsp" %>
<div style="position: relative;left: 230px;top:-10px;width: 1270px">
  <div class="row">
    <div class="col-md-12 col-sm-12 col-xs-12">
      <div class="x_panel">
        <div class="x_title">
          <h2>App 信息维护管理 <i class="fa fa-user"></i> <small>
            <span style="color: red">${dev}</span>
            您可以通过搜索或者其他筛选项对App的信息进行修改，删除等管理操作。</small></h2>
          <div class="clearfix"></div>
        </div>
        <div class="x_content">
          <br />
          <form id="demo-form2" data-parsley-validate class="form-horizontal form-label-left" action="${pageContext.request.contextPath}/app_info/list">
              <input value="${app_info.categoryLevel1}" name="getCategoryLevel1" type="hidden">
              <input value="${app_info.categoryLevel2}" name="getCategoryLevel2" type="hidden">
              <input value="${app_info.categoryLevel3}" name="getCategoryLevel3" type="hidden">
              <ul>
              <li>
            <div class="form-group">
              <label class="control-label col-md-3 col-sm-3 col-xs-12" for="first-name">
                软件名称 <span class="required">*</span>
              </label>
              <div class="col-md-6 col-sm-6 col-xs-12">
                <input type="text" id="first-name" name="softwareName" value="${app_info.softwareName}" class="form-control col-md-7 col-xs-12">
              </div>
            </div>
              </li>
              <li>
            <div class="form-group">
              <label class="control-label col-md-3 col-sm-3 col-xs-12">
                App状态<span class="required">*</span>
              </label>
              <div class="col-md-6 col-sm-6 col-xs-12">
                <select name="status" class="form-control">
                  <option value="0">--请选择--</option>
                  <c:forEach items="${status}" var="status">
                    <option value="${status.valueId}"
                      ${app_info.status==status.valueId?'selected="selected"':''}
                    >${status.valueName}</option>
                  </c:forEach>
                </select>
              </div>
            </div>
              </li>
              <li>
            <div class="form-group">
              <label class="control-label col-md-3 col-sm-3 col-xs-12">
                所属平台</label>
              <div class="col-md-6 col-sm-6 col-xs-12">
                <select name="flatformId" class="form-control">
                  <option value="0">--请选择--</option>
                  <c:forEach items="${flatform}" var="flatform">
                    <option value="${flatform.valueId}"
                      ${app_info.flatformId==flatform.valueId?'selected="selected"':''}
                    >${flatform.valueName}</option>
                  </c:forEach>
                </select>
              </div>
            </div>
              </li>
              <li>
            <div class="form-group">
              <label class="control-label col-md-3 col-sm-3 col-xs-12">
                一级分类</label>
              <div class="col-md-6 col-sm-6 col-xs-12">
                <select name="categoryLevel1" class="form-control" onchange="classifyOne(this.value);" >
                  <option value="0">--请选择--</option>
                  <c:forEach items="${list1}" var="list1">
                    <option value="${list1.id}"
                      ${app_info.categoryLevel1==list1.id?'selected="selected"':''}
                    >${list1.categoryName}</option>
                  </c:forEach>
                </select>
              </div>
            </div>

              </li>
              <li>
            <div class="form-group">
              <label class="control-label col-md-3 col-sm-3 col-xs-12">
                二级分类</label>
              <div class="col-md-6 col-sm-6 col-xs-12">
                <select name="categoryLevel2" class="form-control" onchange="classifyTWO(this.value)">
                </select>
              </div>
            </div>
              </li>
              <li>
            <div class="form-group">
              <label class="control-label col-md-3 col-sm-3 col-xs-12">
                三级分类</label>
              <div class="col-md-6 col-sm-6 col-xs-12">
                <select name="categoryLevel3" class="form-control">
                </select>
              </div>
            </div>
              </li>
              <li></li>
              <li></li>
              <li>
                <p></p>
                <p></p>
            <div class="form-group">
              <div class="col-md-6 col-sm-6 col-xs-12">
                <button type="submit" class="btn btn-success">查詢</button>
              </div>
            </div>
              </li>
            </ul>
          </form>
        </div>
        <div class="x_content">
          <div class="x_panel">
            <a href="${pageContext.request.contextPath}/app_info/dev_add.html" class="btn btn-success">新增APP基础信息</a>
            <table id="datatable" class="table table-striped table-bordered">
              <thead>
              <tr>
                <th>手游名称</th>
                <th>App名称</th>
                <th>手游大小(单位:M)</th>
                <th>所属平台</th>
                <th>所属分类(一级-二级-三级)</th>
                <th>状态</th>
                <th>下载次数</th>
                <th>最新版本</th>
                <th  style="width: 120px;">操作</th>
              </tr>
              </thead>
              <tbody>
              <c:forEach items="${list}" var="list" varStatus="status">
                <tr>
                  <td>${list.softwareName}</td>
                  <td>${list.APKName}</td>
                  <td>${list.softwareSize}</td>
                  <td>${list.flatformName}</td>
                  <td>${list.categoryLevel1Name}->
                      ${list.categoryLevel2Name}->
                      ${list.categoryLevel3Name}
                  </td>
                  <td>${list.statusName}</td>
                  <td>${list.downloads}</td>
                  <td>${list.versionNo}</td>
                  <td>
                    <div class="btn-group">
                      <button type="button" class="btn btn-danger">点击操作</button>
                      <button type="button" class="btn btn-danger dropdown-toggle" data-toggle="dropdown" aria-expanded="false">
                        <span class="caret" style="height: 20px"></span>
                      </button>
                      <ul class="dropdown-menu" role="menu">
                        <c:choose>
                          <c:when test="${list.status==2 || list.status==5}">
                            <li><a href="#">上架</a>
                            </li>
                          </c:when>
                          <c:when test="${list.status==4}">
                            <li><a href="#">下架</a>
                            </li>
                          </c:when>
                        </c:choose>
                        <li><a href="${pageContext.request.contextPath}/app_version/select?appid=${list.id}">新增版本</a>
                        </li>
                        <li><a href="javascript:;" onclick="app_version(${list.status},${list.id})">修改版本</a>
                        </li>
                        <li><a href="javascript:;" onclick="regs(${list.status},${list.id})">修改</a>
                        </li>
                        <li><a href="${pageContext.request.contextPath}/app_info/view?id=${list.id}">查看</a>
                        </li>
                        <li><a href="javascript:;" onclick="del_dev(${list.id});">删除</a>
                        </li>
                        </li>
                      </ul>
                    </div>
                  </td>
                </tr>
              </c:forEach>
              </tbody>
            </table>
            共${page.pageTotal}条记录${page.pageIndex}/${page.pageCount}
            <div style="width:auto;position: absolute; right: 20px;bottom: 10px">
            <c:if test="${page.pageIndex>1}">
              <a class="btn btn-success"
                 href="${pageContext.request.contextPath}/app_info/list?pageIndex=${page.pageIndex-1}">上一页</a>
              <a class="btn btn-success"
                 href="${pageContext.request.contextPath}/app_info/list?pageIndex=1">首页</a>
            </c:if>
            <c:if test="${page.pageIndex<page.pageCount}">
              <a class="btn btn-success"
                 href="${pageContext.request.contextPath}/app_info/list?pageIndex=${page.pageIndex+1}">下一页</a>
              <a class="btn btn-success"
                 href="${pageContext.request.contextPath}/app_info/list?pageIndex=${page.pageCount}">末页</a>
            </c:if>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</div>
<%@ include file="comment/foot.jsp" %>
</body>
<script type="text/javascript">
  //删除
  function del_dev(id) {

    if(confirm("确定要删除吗？")){
      location.href='${pageContext.request.contextPath}/app_info/del?id='+id;
    }

  }
  function app_version(status,appid) {
    if(status==2){
      alert("该APP应用状态为：【审核通过】，不能修改！");
    }
    if(status==4){
      alert("该APP应用状态为：【已上架】，不能修改！");
    }
    if(status==5){
      alert("该APP应用状态为：【已下架】，不能修改！");
    }
    if (status==1||status==3){
      $.getJSON('${pageContext.request.contextPath}/app_version/change?appid='+appid,function (data) {
        if (data.falg==true){
          alert("该APP未上传任何版本信息不能修改！");
        }else {
          location.href='${pageContext.request.contextPath}/app_version/version_change?appid='+appid;
        }
      });
    }
  }
  function regs(status,id) {
    if(status==2){
      alert("该APP应用状态为：【审核通过】，不能修改！");
    }
    if(status==4){
      alert("该APP应用状态为：【已上架】，不能修改！");
    }
    if(status==5){
      alert("该APP应用状态为：【已下架】，不能修改！");
    }
    if(status==1||status==3){
      location.href='${pageContext.request.contextPath}/app_info/query?id='+id;
    }
  }
    function classifyOne(categoryLeve) {
        var CategoryLevel1=$("[name=getCategoryLevel1]").val();
        var CategoryLevel2=$("[name=getCategoryLevel2]").val();
        var CategoryLevel3=$("[name=getCategoryLevel3]").val();
      if($("[name=categoryLevel1]").val()==0){
        $("[name=categoryLevel2]").html("");
        $("[name=categoryLevel3]").html("");
      }
        $("[name=categoryLevel2]").html("");
        $.getJSON('${pageContext.request.contextPath}/app_info/categroyleve1?id='+categoryLeve,function (data) {
          var options='';
          if($("[name=categoryLevel1]").val()!=0) {
             options += '<option value="0">--请选择--</option>';
          }
            for (var i=0;i<data.length;i++){
                if(data[i].id==CategoryLevel2){
                    options+='<option value="'+data[i].id+'"\n' +
                        '>'+data[i].categoryName+'</option>';
                }
                options+='<option value="'+data[i].id+'"\n' +
                    '>'+data[i].categoryName+'</option>';
            }
            $("[name=categoryLevel2]").append(options);
        });
    }
    function classifyTWO(categoryLeve) {
        var CategoryLevel1=$("[name=getCategoryLevel1]").val();
        var CategoryLevel2=$("[name=getCategoryLevel2]").val();
        var CategoryLevel3=$("[name=getCategoryLevel3]").val();
        $("[name=categoryLevel3]").html("");
        var options='<option value="0">--请选择--</option>';
        $.getJSON('${pageContext.request.contextPath}/app_info/categroyleve1?id='+categoryLeve,function (data) {
            for (var i=0;i<data.length;i++){
                if(data[i].id==CategoryLevel3){
                    options+='<option value="'+data[i].id+'"\n' +
                        '>'+data[i].categoryName+'</option>';
                }
                options+='<option value="'+data[i].id+'"\n' +
                    '>'+data[i].categoryName+'</option>';
            }
            $("[name=categoryLevel3]").append(options);
        });
    }
    $(function () {
        var CategoryLevel1=$("[name=getCategoryLevel1]").val();
        var CategoryLevel2=$("[name=getCategoryLevel2]").val();
        if(CategoryLevel1!=""&&CategoryLevel2!=""&&CategoryLevel2!=0&&CategoryLevel1!=0){
            var options2='<option value="0">--请选择--</option>';
            var options3='<option value="0">--请选择--</option>';
          var CategoryLevel1=$("[name=getCategoryLevel1]").val();
          var CategoryLevel2=$("[name=getCategoryLevel2]").val();
          var CategoryLevel3=$("[name=getCategoryLevel3]").val();
            $.getJSON('${pageContext.request.contextPath}/app_info/categroyleve23?id2='+CategoryLevel1+'&id3='+CategoryLevel2,function (data) {
                for (var i=0;i<data.list2.length;i++){
                    if(data.list2[i].id==CategoryLevel2){
                        options2+='<option value="'+data.list2[i].id+'" selected="selected"\n' +
                            '>'+data.list2[i].categoryName+'</option>';
                    }else {
                    options2+='<option value="'+data.list2[i].id+'"\n' +
                        '>'+data.list2[i].categoryName+'</option>';
                    }
                }
              for (var s=0;s<data.list3.length;s++){
                    if(data.list3[s].id==CategoryLevel3){
                        options3+='<option value="'+data.list3[s].id+'"selected="selected"\n' +
                            '>'+data.list3[s].categoryName+'</option>';
                    }else {
                    options3+='<option value="'+data.list3[s].id+'"\n' +
                        '>'+data.list3[s].categoryName+'</option>';
                    }
                }
                $("[name=categoryLevel2]").append(options2);
                $("[name=categoryLevel3]").append(options3);
            });
        }
    });
</script>
</html>
